package com.google.android.material.button;

import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.PorterDuff.Mode;
import android.graphics.drawable.Drawable;
import android.os.Build.VERSION;
import android.util.AttributeSet;
import android.util.Log;
import androidx.annotation.ColorInt;
import androidx.annotation.ColorRes;
import androidx.annotation.DimenRes;
import androidx.annotation.DrawableRes;
import androidx.annotation.Nullable;
import androidx.annotation.Px;
import androidx.annotation.RestrictTo;
import androidx.appcompat.widget.AppCompatButton;
import androidx.core.view.ViewCompat;
import androidx.core.widget.TextViewCompat;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import o.aqu.d;
import o.aqu.f;
import o.aqu.n;
import o.ar;
import o.arh;
import o.asa;
import o.ash;
import o.asi;
import o.gg;

public class MaterialButton extends AppCompatButton {
    @Px
    private int ʻ;
    private Drawable ʽ;
    @Nullable
    private final arh ˊ;
    private Mode ˋ;
    @Px
    private int ˎ;
    private ColorStateList ˏ;
    @Px
    private int ॱॱ;
    private int ᐝ;

    @Retention(RetentionPolicy.SOURCE)
    public @interface IconGravity {
    }

    public MaterialButton(Context context) {
        this(context, null);
    }

    public MaterialButton(Context context, AttributeSet attributeSet) {
        this(context, attributeSet, d.ʽ);
    }

    public MaterialButton(Context context, AttributeSet attributeSet, int i) {
        super(context, attributeSet, i);
        TypedArray ॱ = asa.ॱ(context, attributeSet, n.ʼʻ, i, f.ͺ, new int[0]);
        this.ˎ = ॱ.getDimensionPixelSize(n.ˇ, 0);
        this.ˋ = ash.ˏ(ॱ.getInt(n.ˉˊ, -1), Mode.SRC_IN);
        this.ˏ = asi.ˊ(getContext(), ॱ, n.ˉˋ);
        this.ʽ = asi.ˎ(getContext(), ॱ, n.ˆ);
        this.ᐝ = ॱ.getInteger(n.ˈˊ, 1);
        this.ʻ = ॱ.getDimensionPixelSize(n.ʿᐝ, 0);
        this.ˊ = new arh(this);
        this.ˊ.ˏ(ॱ);
        ॱ.recycle();
        setCompoundDrawablePadding(this.ˎ);
        ˋ();
    }

    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        if (VERSION.SDK_INT < 21 && ˎ()) {
            this.ˊ.ˋ(canvas);
        }
    }

    @RestrictTo({RestrictTo.d.LIBRARY_GROUP})
    public void setSupportBackgroundTintList(@Nullable ColorStateList colorStateList) {
        if (ˎ()) {
            this.ˊ.ˊ(colorStateList);
        } else if (this.ˊ != null) {
            super.setSupportBackgroundTintList(colorStateList);
        }
    }

    @Nullable
    @RestrictTo({RestrictTo.d.LIBRARY_GROUP})
    public ColorStateList ˊ() {
        if (ˎ()) {
            return this.ˊ.ˋ();
        }
        return super.ˊ();
    }

    @RestrictTo({RestrictTo.d.LIBRARY_GROUP})
    public void setSupportBackgroundTintMode(@Nullable Mode mode) {
        if (ˎ()) {
            this.ˊ.ˋ(mode);
        } else if (this.ˊ != null) {
            super.setSupportBackgroundTintMode(mode);
        }
    }

    @Nullable
    @RestrictTo({RestrictTo.d.LIBRARY_GROUP})
    public Mode ॱ() {
        if (ˎ()) {
            return this.ˊ.ˎ();
        }
        return super.ॱ();
    }

    public void setBackgroundTintList(@Nullable ColorStateList colorStateList) {
        setSupportBackgroundTintList(colorStateList);
    }

    @Nullable
    public ColorStateList getBackgroundTintList() {
        return ˊ();
    }

    public void setBackgroundTintMode(@Nullable Mode mode) {
        setSupportBackgroundTintMode(mode);
    }

    @Nullable
    public Mode getBackgroundTintMode() {
        return ॱ();
    }

    public void setBackgroundColor(@ColorInt int i) {
        if (ˎ()) {
            this.ˊ.ˏ(i);
        } else {
            super.setBackgroundColor(i);
        }
    }

    public void setBackground(Drawable drawable) {
        setBackgroundDrawable(drawable);
    }

    public void setBackgroundResource(@DrawableRes int i) {
        Drawable drawable = null;
        if (i != 0) {
            drawable = ar.ˋ(getContext(), i);
        }
        setBackgroundDrawable(drawable);
    }

    public void setBackgroundDrawable(Drawable drawable) {
        if (!ˎ()) {
            super.setBackgroundDrawable(drawable);
        } else if (drawable != getBackground()) {
            Log.i("MaterialButton", "Setting a custom background is not supported.");
            this.ˊ.ˏ();
            super.setBackgroundDrawable(drawable);
        } else {
            getBackground().setState(drawable.getState());
        }
    }

    public void onLayout(boolean z, int i, int i2, int i3, int i4) {
        super.onLayout(z, i, i2, i3, i4);
        if (VERSION.SDK_INT == 21 && this.ˊ != null) {
            this.ˊ.ˊ(i4 - i2, i3 - i);
        }
    }

    protected void onMeasure(int i, int i2) {
        super.onMeasure(i, i2);
        if (this.ʽ != null && this.ᐝ == 2) {
            int measuredWidth = (((((getMeasuredWidth() - ((int) getPaint().measureText(getText().toString()))) - ViewCompat.ᐝ(this)) - (this.ʻ == 0 ? this.ʽ.getIntrinsicWidth() : this.ʻ)) - this.ˎ) - ViewCompat.ʻ(this)) / 2;
            if (ˏ()) {
                measuredWidth = -measuredWidth;
            }
            if (this.ॱॱ != measuredWidth) {
                this.ॱॱ = measuredWidth;
                ˋ();
            }
        }
    }

    private boolean ˏ() {
        return ViewCompat.ʼ(this) == 1;
    }

    public void ˏ(Drawable drawable) {
        super.setBackgroundDrawable(drawable);
    }

    public void setIconPadding(@Px int i) {
        if (this.ˎ != i) {
            this.ˎ = i;
            setCompoundDrawablePadding(i);
        }
    }

    public void setIconSize(@Px int i) {
        if (i < 0) {
            throw new IllegalArgumentException("iconSize cannot be less than 0");
        } else if (this.ʻ != i) {
            this.ʻ = i;
            ˋ();
        }
    }

    public void setIcon(Drawable drawable) {
        if (this.ʽ != drawable) {
            this.ʽ = drawable;
            ˋ();
        }
    }

    public void setIconResource(@DrawableRes int i) {
        Drawable drawable = null;
        if (i != 0) {
            drawable = ar.ˋ(getContext(), i);
        }
        setIcon(drawable);
    }

    public void setIconTint(@Nullable ColorStateList colorStateList) {
        if (this.ˏ != colorStateList) {
            this.ˏ = colorStateList;
            ˋ();
        }
    }

    public void setIconTintResource(@ColorRes int i) {
        setIconTint(ar.ˊ(getContext(), i));
    }

    public void setIconTintMode(Mode mode) {
        if (this.ˋ != mode) {
            this.ˋ = mode;
            ˋ();
        }
    }

    private void ˋ() {
        if (this.ʽ != null) {
            this.ʽ = this.ʽ.mutate();
            gg.ॱ(this.ʽ, this.ˏ);
            if (this.ˋ != null) {
                gg.ˋ(this.ʽ, this.ˋ);
            }
            this.ʽ.setBounds(this.ॱॱ, 0, (this.ʻ != 0 ? this.ʻ : this.ʽ.getIntrinsicWidth()) + this.ॱॱ, this.ʻ != 0 ? this.ʻ : this.ʽ.getIntrinsicHeight());
        }
        TextViewCompat.ॱ(this, this.ʽ, null, null, null);
    }

    public void setRippleColor(@Nullable ColorStateList colorStateList) {
        if (ˎ()) {
            this.ˊ.ˋ(colorStateList);
        }
    }

    public void setRippleColorResource(@ColorRes int i) {
        if (ˎ()) {
            setRippleColor(ar.ˊ(getContext(), i));
        }
    }

    public void setStrokeColor(@Nullable ColorStateList colorStateList) {
        if (ˎ()) {
            this.ˊ.ॱ(colorStateList);
        }
    }

    public void setStrokeColorResource(@ColorRes int i) {
        if (ˎ()) {
            setStrokeColor(ar.ˊ(getContext(), i));
        }
    }

    public void setStrokeWidth(@Px int i) {
        if (ˎ()) {
            this.ˊ.ˎ(i);
        }
    }

    public void setStrokeWidthResource(@DimenRes int i) {
        if (ˎ()) {
            setStrokeWidth(getResources().getDimensionPixelSize(i));
        }
    }

    public void setCornerRadius(@Px int i) {
        if (ˎ()) {
            this.ˊ.ˊ(i);
        }
    }

    public void setCornerRadiusResource(@DimenRes int i) {
        if (ˎ()) {
            setCornerRadius(getResources().getDimensionPixelSize(i));
        }
    }

    public void setIconGravity(int i) {
        this.ᐝ = i;
    }

    private boolean ˎ() {
        return (this.ˊ == null || this.ˊ.ॱ()) ? false : true;
    }
}
